package dryven.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class StreamCopier {
	private InputStream _input;
	private OutputStream _output;
	private int _bufferSize;
	
	public StreamCopier(InputStream input, OutputStream output) {
		this(input,output,10*1024);
	}
	
	public StreamCopier(InputStream input, OutputStream output, int bufferSize) {
		_input = input;
		_output = output;
		_bufferSize = bufferSize;
	}
	
	public void copy() {
		byte[] buffer = new byte[_bufferSize];
		int bytesRead = 0;
		
		try {
			while((bytesRead = _input.read(buffer))!=-1) {
				_output.write(buffer, 0, bytesRead);
			}
			_output.flush();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
}
